package com.ruoyi.dynamic.service.impl;

import com.ruoyi.dynamic.domain.PwDynamic;
import com.ruoyi.dynamic.domain.PwLike;
import com.ruoyi.dynamic.mapper.PwLikeMapper;
import com.ruoyi.dynamic.service.IPwLikeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class PwLikeServiceImpl implements IPwLikeService {
    @Resource
    private PwLikeMapper pwLikeMapper;
    @Resource
    private PwDynamicServiceImpl pwDynamicService;
    @Override
    public int delete(PwLike pwLike) {
        //先查询动态
        PwDynamic pwDynamic = pwDynamicService.selectPwDynamicById(pwLike.getDynamicId());
        pwDynamic.setLikeNumber(pwDynamic.getLikeNumber()-1);
        pwDynamicService.updatePwDynamic(pwDynamic);
        return pwLikeMapper.delete(pwLike);
    }

    @Override
    public int add(PwLike pwLike) {
        PwDynamic pwDynamic = pwDynamicService.selectPwDynamicById(pwLike.getDynamicId());
        pwDynamic.setLikeNumber(pwDynamic.getLikeNumber()+1);
        pwDynamicService.updatePwDynamic(pwDynamic);
        return pwLikeMapper.add(pwLike);
    }
}
